package ZuoYe02_FangFa_0429;

import java.util.Scanner;

//4:Triangle三角形有三个边长的属性，
//定义方法checkValid,检查是否能构成合法的三角形，返回boolean（任意两边的长大于第三边）；
//定义方法，getArea():利用海伦公式计算面积（开根号用Math.sqrt方法实现,公式的实现参考baidu）,
//返回double
public class Triangle {

	double a;
	double b;
	double c;

	int x;
	int y;

	public boolean checkValid() {
		if ((a + b > c) && (a + c > b) && (b + c > a)) {
			return true;
		} else {
			return false;
		}
	}

	public double getArea() {
		double p = (a + b + c) / 2;
		double s = Math.sqrt(p * (p - a) * (p - b) * (p - c));
		return s;
	}

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		Triangle tri = new Triangle();

		while (true) {
			System.out.print("请输入三角形的第一个边长：");
			tri.a = input.nextDouble();
			System.out.print("请输入三角形的第二个边长：");
			tri.b = input.nextDouble();
			System.out.print("请输入三角形的第三个边长：");
			tri.c = input.nextDouble();

			if (tri.checkValid()) {
				System.out.println(tri.a + "," + tri.b + "," + tri.c + "能组成三角形");
				break;
			} else {
				System.out.println(tri.a + "," + tri.b + "," + tri.c + "不能组成三角形");
			}

		}

		System.out.println(tri.a + "," + tri.b + "," + tri.c + "组成三角形的面积是：" + tri.getArea());

	}

}
